package com.session01;

import java.util.Scanner;

public class Demo2 {
    public static void main(String[] args) {
        int[] arr = {12, 23, 34, 45, 56, 67, 78, 89};
        Scanner num = new Scanner(System.in);
        int n = num.nextInt();
        int flag = 0;
        for (int i = 0; i < arr.length; i++) {
            if (n != arr[i]) {
                flag++;
            }
        }
        if (flag == arr.length - 1) {
            int[] array = delete(arr, n);
            for (int element : array) {
                System.out.print(element + " ");
            }
        } else {
            System.out.println("该数不在数组中，无法删除！");
        }
    }

    public static int[] delete(int[] arr, int n) {
        int len = arr.length;
        int[] temp = new int[len - 1];
        int flag = 0;
        for (int i = 0; i < len; i++) {
            if (n == arr[i]) {
                flag = i;
                break;
            }
        }
/*        for (int i = 0; i < flag; i++) {
            temp[i] = arr[i];
        }
        for (int i = flag; i < temp.length; i++) {
            temp[i] = arr[i + 1];
        }*/
        for (int i = 0; i < temp.length; i++) {
            if (i < flag) {
                temp[i] = arr[i];
            } else {
                temp[i] = arr[i + 1];
            }
        }
        System.out.println("该数在数组中");
        return temp;
    }
}
